﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using System.Windows.Forms;

namespace DAO
{
    public class ChiTietDoanhThuTheoLoaiPhongDAO
    {
         public static void LayChiTietBaoCaoDoanhThuTheoLoaiPhong(int[] cacMaDoanhThu, ListView lv)
        {
            DataProvider dp = new DataProvider();
            for (int i = 0; i < cacMaDoanhThu.Length; i++)
            {
                string sql = "Select lp.TenLoaiPhong, ct.DoanhThu, ct.TyLe From CHITIETBAOCAODOANHTHU ct, LoaiPhong lp Where ct.MaLoaiPhong=lp.MaLoaiPhong and ct.MaBaoCaoDoanhThu=" + cacMaDoanhThu[i];
                DataTable dt = dp.ExecuteQuery(sql);
                int stt = 1;
                foreach (DataRow dr in dt.Rows)
                {
                    ListViewItem lvit = new ListViewItem(stt.ToString());
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j == dt.Columns.Count - 1)
                        {
                            lvit.SubItems.Add(dr[j].ToString() + " %");
                            break;
                        }
                        lvit.SubItems.Add(dr[j].ToString());
                    }
                    lv.Items.Add(lvit);
                    stt++;
                }
            }
        }

        public static DataTable GetAll()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select * From CHITIETBAOCAODOANHTHU";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static void ThemChiTietDoanhThuTheoLoaiPhong(ChiTietDoanhThuTheoLoaiPhongDTO ctdt)
        {
            string sql = string.Format("INSERT INTO CHITIETBAOCAODOANHTHU (MaChiTietBaoCaoDoanhThu, MaBaoCaoDoanhThu, MaLoaiPhong, DoanhThu, TyLe) VALUES (" + ctdt.MaChiTietBaoCaoDoanhThu + ", " + ctdt.MaBaoCaoDoanhThu + ", " + ctdt.MaLoaiPhong + ", " + ctdt.DoanhThu + ", " + ctdt.TyLe + ")");
            DataProvider.ExecuteNonQuery(sql);
        }
    }
}
